package com.wtwd.campus.receiver;

import com.wtwd.campus.entity.MqCallNoteMessage;
import com.wtwd.campus.entity.MqLocationData;
import com.wtwd.campus.service.IRMFeignClientService;
import com.wtwd.campus.service.InjectFeignService;
import com.wtwd.campus.utils.LocationUtils;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

public class UploadMonitorRecordsReceiver implements Receiver {
    @Autowired
    private IRMFeignClientService irmFeignClientService;
    @Override
    public String parseMessage(String data) {
        // *WT,866248053277370,MONITORNOTE,175029,18797874506,4,A,2250.2864,N,11391.5772,E,1.56,149,170721,FDFFFFFF#
        String[] split = data.split(",");
        String imei=split[1];
        String messageType = split[2];
        String commandNumber=split[3];
        String monitorNum=split[4];//监听人手机号码
        String monitorTime=split[5];//监听时长
        String lat = split[7];
        String lng = split[9];
        String speed = split[11];
        String orientation = split[12];
        String date = split[13];//日月年
        String deviceStatus = split[14];//设备状态
        List<Double> list = LocationUtils.transiformLatAndLng(lng, lat);
        MqCallNoteMessage mqCallNoteMessage = new MqCallNoteMessage();
        mqCallNoteMessage.setCommandNumber(commandNumber);
        mqCallNoteMessage.setDeviceDate(date);
        mqCallNoteMessage.setDeviceTime(commandNumber);
        mqCallNoteMessage.setPhone(monitorNum);
        mqCallNoteMessage.setDuration(monitorTime);
        mqCallNoteMessage.setImei(imei);
        MqLocationData mqLocationData = new MqLocationData();
        mqLocationData.setOrientation(Integer.parseInt(orientation));
        mqLocationData.setSpeed(Double.parseDouble(speed));
        mqLocationData.setLatitude(list.get(1));
        mqLocationData.setLongitude(list.get(0));
        mqCallNoteMessage.setMqLocationData(mqLocationData);
        InjectFeignService.getIrmFeignClientService().monitorNoteMessage(mqCallNoteMessage);
        return imei;
    }
}
